﻿#include "yzrutil.h"

#ifdef USEJNI
#include "JNIUtil.h"
namespace yzrilyzr_util {
	DoubleArray* jDoubleArray2DoubleWithLength(JNIEnv* env, jdoubleArray jd) {
		jdouble* elements = env->GetDoubleArrayElements(jd, nullptr);
		int32_t length = env->GetArrayLength(jd);
		if (elements == nullptr) {
			std::cerr << "Buffer nullptr" << std::endl;
			return nullptr;
		}
		DoubleArray* dl = new DoubleArray(length);
		memcpy(dl->array, elements, dl->length * 8);
		env->ReleaseDoubleArrayElements(jd, elements, 0);
		return dl;
	}
	
}
using namespace yzrilyzr_util;
JNIEXPORT jlong JNICALL Java_yzrilyzr_util_JNIUtil_generateDoubleArray(JNIEnv* env, jobject, jdoubleArray jd)
{
	return reinterpret_cast<jlong>(jDoubleArray2DoubleWithLength(env, jd));
}
#endif